
package com.yimixian.app.activity;

import com.umeng.analytics.MobclickAgent;
import com.yimixian.app.R;
import com.yimixian.app.SystemFramework;
import com.yimixian.app.common.StatConstants;
import com.yimixian.app.ui.GuidelinesView;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.animation.AccelerateInterpolator;

public class GuideActivity extends Activity {
    private GuidelinesView mGuidelinesView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide_layout);
        mGuidelinesView = (GuidelinesView) findViewById(R.id.guidelines_view);
        showGuideLine();
    }

    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart(this.getClass().getSimpleName());
        MobclickAgent.onResume(this);
    }

    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd(this.getClass().getSimpleName());
        MobclickAgent.onPause(this);
    }

    @Override
    protected void onPostResume() {
        super.onPostResume();
    }

    public static Intent buildIntent(Context context) {
        Intent intent = new Intent(context, GuideActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
        return intent;
    }

    public void showGuideLine() {
        mGuidelinesView.setListener(new GuidelinesView.Listener() {
            @Override
            public void onCompleteButtonClicked() {
                MobclickAgent.onEvent(GuideActivity.this,
                        StatConstants.HOME_GUIDE_LINE_COMPLETE_CLICK);
                startActivity(YMXMainActivity.buildIntent(SystemFramework
                        .getInstance().getGlobalContext()));
                finish();

//                ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f);
//                animator.setDuration(10);
//                animator.setInterpolator(new AccelerateInterpolator());
//                animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
//                    @Override
//                    public void onAnimationUpdate(ValueAnimator animation) {
//                        float alpha = (float) animation.getAnimatedValue();
//                        mGuidelinesView.setAlpha(1f - alpha);
//                    }
//                });
//                animator.addListener(new AnimatorListenerAdapter() {
//                    @Override
//                    public void onAnimationEnd(Animator animation) {
//                        startActivity(YMXMainActivity.buildIntent(SystemFramework
//                                .getInstance().getGlobalContext()));
//                        finish();
//                    }
//                });
//                animator.start();
            }
        });
    }
}
